package cn.elwy.rcp.ui.explorer.create.wizard;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import cn.elwy.rcp.ui.explorer.composite.ReleaseComposite;
import cn.elwy.rcp.ui.explorer.core.vo.FtpInfo;
import cn.elwy.rcp.ui.explorer.core.vo.ProjectConfig;
import cn.elwy.rcp.ui.wizard.BaseWizardPage;

public class ReleaseWizardPage extends BaseWizardPage {

	public static final String ID = "ReleaseWizardPage";
	private ReleaseComposite composite;
	private ProjectConfig projectConfig;

	/**
	 * Create the wizard.
	 */
	public ReleaseWizardPage() {
		super(ID);
		setTitle("发布、部署配置");
		setDescription("配置发布、部署地址及端口用户等信息");
	}

	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = createUI(parent);
		setControl(container);

		addListener();
		init();

	}

	private Composite createUI(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);
		container.setLayout(new GridLayout(1, false));

		composite = new ReleaseComposite(container, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		return container;
	}

	private void addListener() {
	}

	private void init() {
		projectConfig = ((NewBuilderProjectWizard) getWizard()).getProjectConfig();
	}

	@Override
	protected boolean validate() {
		return super.validate();
	}

	public Object getPageData() {
		FtpInfo release = composite.getRelease();
		projectConfig.setRelease(release);
		List<FtpInfo> deployList = composite.getDeployList();
		projectConfig.setDeployList(deployList);
		return projectConfig;
	}

}
